modelit.layout.Node

Extends: hgsetget & handle & matlab.mixin.Heterogeneous

A node in a tree data structure.
A node may have at most one parent and zero or more children.
A node with no parent is the root of its tree; a node with no children is a leaf.

Properties

allowsChildren

  True if the node is able to have children.
  Boolean, default value: true

children (Read-only)

  Array of children,
  May be [] if this node has no children.
  Children are ordered according to their rank.
  Array, default value: []

parent

  This node's parent, or empty if this node has no parent.
  modelit.layout.Node or [], default value: []

rank

  Relative position of the node
  When ordering horizontally: low rank goes left. High rank goes right.
  When ordering vertically. Low rank goes above. High rank goes below.
  NOTE: only the relative ranks are important.
  Integer, default value: 0

Methods

Node

Modelit.layout.Node constructor.


CALL:

   obj = modelit.layout.Node(allowsChildren)
 

INPUT:

   allowsChildren:
    boolean, true if this node can have children.
 

OUTPUT:

   obj:
     modelit.layout.Node

getPathToRoot

Builds the parents of node up to and including the root node, where the original node is the last element in the returned array.


CALL:

   value = getPathToRoot(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     list of modelit.layout.Node

getLevel

Returns the number of levels above this node, i.e. the distance from the root to this node.


CALL:

   value = getLevel(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     integer

getDepthFirstList

First order for the subtree starting at the specified node.


CALL:

   list = getDepthFirstList(obj, list)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   list:
     array of modelit.layout.Node in depth-first order

getBreadthFirstList

First order for the subtree starting at the specified node.


CALL:

   list = getBreadthFirstList(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   list:
     array of modelit.layout.Node in breadth-first order

getPreviousSibling

Returns the previous sibling of this node.
Returns [] if this node has no parent or if it is the parent's first child.


CALL:

   value = getPreviousSibling(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     modelit.layout.Node or []

getNextSibling

Returns the next sibling of this node.
Returns [] if this node has no parent or if it is the parent's last child.


CALL:

   value = getNextSibling(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     modelit.layout.Node or []

getSiblings

Gets the siblings (nodes with the same parent) of this node.
Note that this node is its own sibling


CALL:

   value = getSiblings(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     modelit.layout.Node

removeAllChildren

Removes all of this node's children.


CALL:

   removeAllChildren(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   No output

add

Removes newChild from its parent and makes it a child of this node by adding it to the end of this node's child array.


CALL:

   add(obj, newChild)
 

INPUT:

   obj:
     modelit.layout.Node
   newChild:
     modelit.layout.Node, node to be added as a child of obj
 

OUTPUT:

   No output

isRoot

Returns true if this node is the root of the tree.


CALL:

   obj = isRoot(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
    boolean, true if this node is a root node

isLeaf

Returns true if this node is a leaf.


CALL:

   value = isLeaf(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
    boolean, true if this node is a leaf (has no children)

getRoot

Returns the root of this node.


CALL:

   obj = getRoot(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   obj:
     modelit.layout.Node

getIndex

Returns the index of this node in its parent's children.


CALL:

   value = getIndex(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     integer with index of this node in its parent's children, 0 if this node is a root

getChildCount

Returns the number of children of this node.


CALL:

   value = getChildCount(obj)
 

INPUT:

   obj:
     modelit.layout.Node
 

OUTPUT:

   value:
     integer with number of children of this node

getChildAt

Returns the child of obj at index childIndex.


CALL:

   value = getChildAt(obj, childIndex)
 

INPUT:

   obj:
     modelit.layout.Node
   childIndex:
     integer
 

OUTPUT:

   obj:
     modelit.layout.Node or [] if index exceeds number of children

eq

  Returns the objects whose property values match those passed as param-value pairs to the findobj command.

findobj

  Returns the objects whose property values match those passed as param-value pairs to the findobj command.

remove

Removes this node and its children from the tree.


CALL:

   remove(obj)
 

INPUT:

   obj:
     modelit.layout.Node, node to remove from tree
 

OUTPUT:

   No output